package org.itzheng.database;

import android.content.Context;

/**
 * Title:数据库工具类<br>
 * Description: <br>
 * 在 Application 中初始化后，就不用每次使用都去获取数据库
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2020-6-30.
 */
public class MyDataBaseUtils {
    private static MyDataBase mDataBase;

    /**
     * 初始化数据库
     *
     * @param context
     */
    public static void initDataBase(Context context) {
        mDataBase = MyDataBase.getDatabase(context);
    }

    /**
     * 获取数据库
     *
     * @return
     */
    public static MyDataBase getDataBase() {
        if (mDataBase == null) {
            //如果数据库为空则抛异常
            throw new NullPointerException("MyDataBase is null,please init");
        }
        return mDataBase;
    }
}
